﻿using JX.Core.Entity;
using JX.Infrastructure.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace JXWebSite.Areas.Admin.Models.UserViewModels
{
	/// <summary>
	/// 用户资金、积分、有效期和点券的视图类
	/// </summary>
	public class EncourageStrategyViewModel
	{
		/// <summary>
		/// 激励类型：0：资金；1：积分；2：点券；3：有效期；
		/// </summary>
		[Required(ErrorMessage = "激励类型不能为空")]
		public int eType { get; set; } = 0;

		/// <summary>
		/// 操作类型
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string eAction { get; set; } = "Add";

		/// <summary>
		/// ID类型：0：所有会员；1：会员ID；2：会员名；3：会员组；
		/// </summary>
		[Required(ErrorMessage = "会员类型不能为空")]
		public int IdType { get; set; } = 0;
		/// <summary>
		/// 
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string ids { get; set; } = string.Empty;
		/// <summary>
		/// 
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string UserName { get; set; } = string.Empty;
		/// <summary>
		/// 
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string GroupIDs { get; set; } = string.Empty;
		/// <summary>
		/// 
		/// </summary>
		[Required(ErrorMessage = "数量不能为空")]
		[Range(1,int.MaxValue,ErrorMessage ="必须大于0")]
		public int HowMany { get; set; }
		/// <summary>
		/// 
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string Remark { get; set; } = string.Empty;
		/// <summary>
		/// 
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string Memo { get; set; } = string.Empty;
		/// <summary>
		/// 操作别名
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string ActionAlias
		{
			get
			{
				string alias = (string.Compare(eAction, "Minus", StringComparison.OrdinalIgnoreCase) == 0) ? "减少" : "增加";
				switch (eType)
				{
					case 0:
						alias += "资金";
						break;
					case 1:
						alias += "积分";
						break;
					case 2:
						alias += ConfigHelper.Get<UserConfig>().PointName;
						break;
					case 3:
						alias += "有效期";
						break;
				}
				return alias;
			}
		}
	}
}
